from typing import Union

from qfluentwidgets.components.dialog_box.mask_dialog_base import MaskDialogBase
from qtpy.QtGui import QPixmap, QImage
from qtpy.QtWidgets import QVBoxLayout

from ..widgets import PictureBrowserView


class PictureBrowserDialog(MaskDialogBase):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.verticalLayout = QVBoxLayout(self.widget)
        self.pictureBrowser = PictureBrowserView(self.widget)

        self._hBoxLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.addWidget(self.pictureBrowser)
        self.widget.setGraphicsEffect(None)

        self.pictureBrowser.closeSignal.connect(self.closeSignal)

    def closeSignal(self):
        self.pictureBrowser.close()
        self.close()

    def setPixmap(self, pixmap: Union[str, QPixmap, QImage]):
        self.pictureBrowser.setPixmap(pixmap)
